var log = (...arg) => console.log.call(console, ...arg)
// 简单原型链继承
function Person () {}

function Student () {}

Student.prototype = new Person();
Student.prototype.constructor = Student;

var a = new Student();
log(a instanceof Student)
log(a instanceof Person)

// 复杂原型链继承
function Person (name = 'unknow', age = 0) {
  this.name = name;
  this.age = age;
}
Person.prototype.say = function () {
  log(`I am a person`);
}

function Student (name) {
  this.name = name;
  this.score = 90;
}

Student.prototype = new Person();
Student.prototype.constructor = Student;
Student.prototype.study = function () {
  log(`I am studing`);
}

var stu = new Student('lucy');
log(stu.name, stu.age, stu.score);
stu.say();
stu.study();

// 1. 原型链继承所存在的问题

function Person() { this.songs = ['国歌'] }
function Student(category) { this.category = category }
Student.prototype = new Person();
// 修复构造函数
Student.prototype.constructor = Student;
var music = new Student('音乐系');
var pupil = new Student('幼儿园');
console.log(music.songs); // 国歌
console.log(pupil.songs); // 国歌
// 音乐系学习了新的歌曲“流行音乐”
music.songs.push('流行音乐');
console.log(pupil.songs); // 国歌,流行音乐
// 由于Student子类的原型链是同一个Person对象，则他们的songs是共享的，所以就会出现问题

// 2. 原型链继承，创建Student实例时，不能向Person传参
// 因为 Student的原型链是Person的一个对象

